package com.jackstraw.jack_base.datasource.elasticsearch.entity;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jackstraw.jack_base.datasource.elasticsearch.aspect.annotation.SearchFind;
import com.jackstraw.jack_base.datasource.elasticsearch.util.ElasticSearchUtil;
import com.jackstraw.jack_base.util.ObjectUtil;
import com.jackstraw.jack_base.util.entity.BaseEntity;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@Data
public class ElasticSearchBaseEntity<T> extends BaseEntity<T> {

    /**
     * 序列化号
     */
    private static final long serialVersionUID = 7231021186278058888L;


    /**
     * 主键标识
     */
    @Field(store = true, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word", type = FieldType.Text)
    protected String id;

    /**
     * 检索字符串
     */
    @JsonIgnore
    private String findStr;

    /**
     * 起始索引
     * <p>
     * 从0开始
     */
    @JsonIgnore
    private Integer startIndex;

    /**
     * 页码
     * <p>
     * 从0开始
     */
    @JsonIgnore
    private Integer pageNum = 0;

    /**
     * 每页记录数
     */
    @JsonIgnore
    private Integer pageSize;

    /**
     * 排序
     */
    @JsonIgnore
    private Sort sort;

    /**
     * 页码工具类
     */
    @JsonIgnore
    private Pageable pageable;

    /**
     * 要查询的字段
     */
    @JsonIgnore
    private List<String> includeFields;

    /**
     * 要排除的字段
     */
    @JsonIgnore
    private List<String> excludeFields;


    /**
     * 要删除的ID集合
     */
    @JsonIgnore
    private List<String> ids;

    public Integer getStartIndex() {
        if (ObjectUtil.ObjectUtilByLang3.isEmpty(this.startIndex)) {
            return this.pageNum * this.pageSize;
        }
        return startIndex;
    }

    public Pageable getPageable() {
        return pageable;
    }
}
